Skip to content

feat(shader): implement s_swappc_b64 null, long branches and dword jump tables - #754

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Celegans12:feat/shader-swappc-null-setpc
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Celegans12:feat/shader-swappc-null-setpc

Conversation

@Celegans12

Copy link
Copy Markdown
Contributor

What

The decoder threw unsupported SOP1 opcode 33 on s_swappc_b64 null, s[N:N+1] (0xbefd21NN), and GraphBuilder could not resolve the jumps built around it.

  • SOP1 opcode 33 with SDST null decodes as s_setpc_b64: S_SWAPPC_B64 is D.u64 = PC + 4; PC = S0.u64 (RDNA2 ISA) and null drops the write, as in KytyPS5 DecodeSop1. A real destination (a call) still throws.
  • Long branch: s_getpc_b64, then s_add_u32/s_addc_u32 or s_sub_u32/s_subb_u32 immediates on the same pair (also vcc); the target is the exact 64-bit result, and a jump into the sequence throws.
  • Dword jump table: target = base - s_load_dword entry, with the base from s_getpc_b64/s_add_u32/s_addc_u32 0 and the index bounded by s_min_u32 (at most 255) and scaled by s_lshl_b32 2. The resolver follows the last write of each register through straight-line code, so other code may sit between the steps; anything else is refused. Lowered like the 64-bit tables of feat(shader): lower bounded PC-relative jump tables #141; the code table load now also takes one-dword entries.
  • PPSA26344 v1.008 all_shaders.xpps: 6 long branches and 25 tables in 11 programs, e.g. 32ac8b907b12797b 0x144 beea1f00 806aff6a 0002ee98 826b806b befd216a, 2bb3e36a02c36373 0x208 (15 entries, v_cmp writes between load and jump), 22cccef7ba602287 0x67ec (index in vcc_lo, load offset 0x50).
  • This also unblocks tessellation M3: the 7 LS front programs end with s_swappc_b64 null, s[6:7] (0xbefd2106), where DecodeRdnaFrontProgram now stops.
  • feat(shader): implement waitcnt counter variants #387 edits resolveJumpTable (waitcnt variants); this PR does not touch that function and merges cleanly with it.
  • feat(shader): implement S_BFE_I64 #234 adds s_bfe_i64 to the same decoder file; the two merge cleanly.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 681f83e: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 317/317 tests pass (ctest --output-on-failure)
  • Extended agc_shader_control_flow (decode, front program, table values and targets, both long branches, structurize and recompile, 8 refusals) and new agc_driver_scalar_swappc (all four shapes on the GPU, wave32 and wave64). Both fail on main with unsupported SOP1 opcode 33.
  • PPSA26344 v1.008 offline sweep: all 11 programs, which failed at decode, now decode and build their graphs, then stop at runtime-indexed descriptors or at state the harness lacks; 3ba7ffa5ac5a098a passes spirv-val with null descriptors. cd88a1ad0e8964d4 (6 tables of 98 entries) spends 25 minutes in Structurizer::Structurize, and 32ac8b907b12797b (10 tables) does not finish it in 90 minutes.
  • Not tested: PPSA21564 (gate not run; expect it), Dreaming Sarah, Linux (CI), console behaviour.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

…mp tables

SOP1 opcode 33 with SDST null keeps no return address, so it is exactly
s_setpc_b64; the decoder now reads it that way, as KytyPS5 does. A call
with a real destination still throws "unsupported SOP1 opcode 33".

GraphBuilder resolves two more jump shapes. A long branch is
s_getpc_b64 and s_add_u32/s_addc_u32 or s_sub_u32/s_subb_u32
immediates, also through vcc, all in one block. A dword jump table
branches to the table base minus an entry that s_load_dword reads at an
index bounded by s_min_u32 and scaled by 4; the resolver follows
register writes back through straight-line code, and anything else is
still refused. The code table load now also handles one-dword entries.

agc_shader_control_flow checks the decode, the graphs and the refusals;
the new agc_driver_scalar_swappc runs all shapes on the GPU.
@Celegans12
Celegans12 force-pushed the feat/shader-swappc-null-setpc branch from 65db9a4 to 41fc6c6 Compare October 5, 2026 20:41
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 5, 2026
@oneandonlydean
oneandonlydean merged commit 8379f09 into boykopovar:main Oct 5, 2026
3 checks passed
@Celegans12
Celegans12 deleted the feat/shader-swappc-null-setpc branch October 5, 2026 23:51
ebosido444-ai added a commit to ebosido444-ai/AnyPS5 that referenced this pull request Oct 7, 2026
Decodes SOP1 0x21 s_swappc_b64 with a real link pair and translates the call: the fetch-shader call at a VS/ES/LS entry is inlined from the parsed fetch-shader plan, and static in-shader call regions lift through the existing s_setpc_b64 return path. boykopovar#754 covers s_swappc null, long branches and jump tables and leaves a real destination (a call) throwing; this fills exactly that gap and makes fetch-shader-entry shaders recompile. Computed targets, link escapes beyond the constant-offset model, unclosable call/return pairing and recursion throw; see docs/dev/TechnicalDebt.md.
ebosido444-ai added a commit to ebosido444-ai/AnyPS5 that referenced this pull request Oct 7, 2026
Decodes SOP1 0x21 s_swappc_b64 with a real link pair and translates the call: the fetch-shader call at a VS/ES/LS entry is inlined from the parsed fetch-shader plan, and static in-shader call regions lift through the existing s_setpc_b64 return path. boykopovar#754 covers s_swappc null, long branches and jump tables and leaves a real destination (a call) throwing; this fills exactly that gap and makes fetch-shader-entry shaders recompile. Computed targets, link escapes beyond the constant-offset model, unclosable call/return pairing and recursion throw; see docs/dev/TechnicalDebt.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants